/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Stock.java
 *
 * Created on 13.05.2011, 17:47:30
 */

package siedleronlineproxy.forms.stock;

import javax.swing.JLabel;
import siedleronlineproxy.IconLoader;
import siedleronlineproxy.constants.Resource;
import siedleronlineproxy.registry.StockRegistry;

/**
 *
 * @author nspecht
 */
public class Stock extends javax.swing.JPanel {
    private static Stock instance = null;
    public static Stock getInstance() {
        return Stock.instance;
    }

    JLabel[] mengen = new JLabel[Resource.Products.__SIZE.ordinal()];
    /** Creates new form Stock */
    public Stock() {
        initComponents();
        myInit();
    }

    public void myInit() {
        Stock.instance = this;
        int cols = 3;
        int items = 2;
        java.awt.GridBagConstraints gridBagConstraints;
        for (int i=0;i<this.mengen.length;i++) {
            JLabel name = new JLabel(Resource.getInstance().names[i]+":");
            name.setIcon(new IconLoader().getIconById(Resource.getInstance().icons[i],"res"));
            this.mengen[i] = new JLabel("0");
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = (i%cols)*items;
            gridBagConstraints.gridy = 1+(i/cols);
            gridBagConstraints.insets = new java.awt.Insets(0, 10, 5, 0);
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
            add(name, gridBagConstraints);
            gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = (i%cols)*items+1;
            gridBagConstraints.gridy = 1+(i/cols);
            gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
            gridBagConstraints.weightx = 1.0;
            gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
            add(this.mengen[i], gridBagConstraints);
        }
    }

    public void update() {
         for (int i=0;i<this.mengen.length;i++) {
             this.mengen[i].setText(""+StockRegistry.getInstance().menge[i]);
         }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setMaximumSize(new java.awt.Dimension(3000, 3000));
        setMinimumSize(new java.awt.Dimension(100, 100));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(100, 100));
        setLayout(new java.awt.GridBagLayout());
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
